<?php

// $Id: developer.inc 24 2010-11-11 07:33:55Z mjohnson60@gmail.com $
//
// $Author: mjohnson60@gmail.com $
// $Date: 2010-10-29 07:27:52 -0400 (Fri, 29 Oct 2010) $
//
// $Rev: 16 $
//


class Developer extends DBObject
{
	// load defaults
	var $did = 0;
	
	var $name = 'anonymous';
	var $email = 'anonymous@anonymous';

	/**
	 * Developer::Developer()
	 * 
	 * This constructor sets up the necessary data that DBObject uses to make queries on the developer database
	 * 
	 * @return
	 */
	public function Developer($data = NULL)
	{
		$this->table = 'developer';
		
		$this->id_name = 'did';
		
		$this->fields = array(
			'name' => "'%s'", 'email' => "'%s'"
		);
		
		parent::DBObject($data);
	}

	/**
	 * Developer::schema()
	 * 
	 * @return
	 */
	public static function schema()
	{
		return 'CREATE TABLE IF NOT EXISTS `developer` (
    			  `did` int(10) unsigned NOT NULL AUTO_INCREMENT,
    			  `name` varchar(45) NOT NULL,
    			  `email` varchar(64) NOT NULL,
    			  PRIMARY KEY (`did`),
    			  UNIQUE KEY `did_UNIQUE` (`did`),
    			  UNIQUE KEY `email_UNIQUE` (`email`)
    			) ENGINE=InnoDB DEFAULT CHARSET=utf8';
	}

	/**
	 * Developer::install()
	 * 
	 * @return
	 */
	public static function install()
	{
		db_query('DROP TABLE IF EXISTS developer');
		$result = db_query(Developer::schema());
		
		if ($result !== FALSE)
		{
			system_set_message('The <code>developer</code> table was successfully created.');
			
			db_query("INSERT INTO developer (name, email) VALUES ('anonymous', 'anonymous@anonymous')");
			db_query("UPDATE developer SET did=0 WHERE email='%s'", 'anonymous@anonymous');
			db_query('ALTER TABLE developer AUTO_INCREMENT=1');
			
			return TRUE;
		}
		else
		{
			system_set_message('The <code>developer</code> table was not created.');
			
			return FALSE;
		}
	}

	/**
	 * Developer::uninstall()
	 * 
	 * @return
	 */
	public static function uninstall()
	{
		$result = db_query('DROP TABLE IF EXISTS developer');
		if ($result !== FALSE)
		{
			system_set_message('The <code>developer</code> table was successfully removed.');
			
			return TRUE;
		}
		else
		{
			system_set_message('The <code>developer</code> table was not removed.');
			
			return FALSE;
		}
	}
}
